package com.bowlong.third;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.bowlong.tool.Lib2;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class FastJSON extends JSON {
	public static final String LIST = "[]";
	public static final String MAP = "{}";

	public static final String toJSONString(Map map) {
		return JSON.toJSONString(map);
	}

	public static final List parseList(String text) {
		if (Lib2.isEmpty(text))
			return new ArrayList();
		return (List) JSON.parse(text);
	}

	public static final Map parseMap(String text) {
		if (Lib2.isEmpty(text))
			return new HashMap();
		return (Map) JSON.parse(text);
	}

	public static final String format(String json) {
		return prettyFormat(json);
	}

	public static final String prettyFormat(String json) {
		Object obj = JSON.parse(json);
		return prettyFormat(obj);
	}

	public static final String format(Object object) {
		return prettyFormat(object);
	}

	public static final String prettyFormat(Object object) {
		boolean prettyFormat = true;
		return JSON.toJSONString(object, prettyFormat);
	}

	public static void main(String[] args) throws IOException {
		List l = new ArrayList();
		{
			Map m = new HashMap();
			m.put("1", "001");
			m.put("name", "张三");
			m.put("sex", "male");
			l.add(m);
		}
		{
			Map m = new HashMap();
			m.put("1", "001");
			m.put("name", "张三");
			m.put("sex", "male");
			l.add(m);
		}

		String s = toJSONString(l);
		System.out.println(prettyFormat(s));
	}
}
